Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Avoid null exception in removeSubquery #147

Merged
merged 1 commit into from
Mar 1, 2024

Conversation

viirya
Copy link
Member

@viirya viirya commented Mar 1, 2024

Which issue does this PR close?

Closes #.

Rationale for this change

In CometScalarSubquery.removeSubquery, we should make sure the planId is still in subqueryMap before we go to delete subquery from it. Otherwise, null exception could be thrown.

What changes are included in this PR?

How are these changes tested?

@@ -47,10 +47,12 @@ public static synchronized void setSubquery(long planId, ScalarSubquery subquery
}

public static synchronized void removeSubquery(long planId, ScalarSubquery subquery) {
subqueryMap.get(planId).remove(subquery.exprId().id());
if (subqueryMap.containsKey(planId)) {
subqueryMap.get(planId).remove(subquery.exprId().id());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hit NPE here while working sort merge join PR. I think it is possible that the query plan has duplicate subqueries (e.g., reused subquery), so if it may try to do removal of subquery after the map was clean up.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It maybe hard to create a test query without join to reproduce it. So I leave a test out here. But this change looks straightforward.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks correct to me.
One possible way to construct such cases:

      val subquery =
        new Column(ScalarSubquery(spark.range(10).selectExpr("max(id)").logicalPlan)).as("subquery")
      val df = spark.range(1000).select($"id", subquery).filter("id == subquery")

Disclaimer: this case is not verified.

Copy link
Contributor

@advancedxy advancedxy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@viirya viirya merged commit 5905151 into apache:main Mar 1, 2024
13 checks passed
@viirya viirya deleted the fix_subquery branch March 1, 2024 05:05
@viirya
Copy link
Member Author

viirya commented Mar 1, 2024

Merged. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants